package com.bbva.kyfb.kyfbjpatlbh.dominiotlbh;

import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

/**
 * The Class Ttlsbont.
 */
@Configurable
@Entity
@Table(name = "TTLSBONT",schema = "TLSB")
@RooJavaBean
@RooToString
@RooEntity(identifierType = TtlsbontPK.class, versionField = "",  persistenceUnit="persistenceUnitTLBH",table = "TTLSBONT", schema = "TLSB")
@PersistenceContext(unitName="persistenceUnitTLBH")
@RooDbManaged(automaticallyDelete = true)
public class Ttlsbont {

	/** The entity manager. */
	@PersistenceContext(unitName="persistenceUnitTLBH")
    transient EntityManager entityManager;

	/** The id. */
	@EmbeddedId
    private TtlsbontPK id;

	@Column(name = "TIM_TIMESTAM", columnDefinition = "DATE")
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date timTimestam;

	@Column(name = "AUD_FMODIFIC", columnDefinition = "DATE")
    @NotNull
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(style = "M-")
    private Date audFmodific;

	@Column(name = "AUD_USUARIO", columnDefinition = "CHAR", length = 8)
    @NotNull
    private String audUsuario;

	public Date getTimTimestam() {
        return this.timTimestam;
    }

	public void setTimTimestam(Date timTimestam) {
        this.timTimestam = timTimestam;
    }

	public Date getAudFmodific() {
        return this.audFmodific;
    }

	public void setAudFmodific(Date audFmodific) {
        this.audFmodific = audFmodific;
    }

	public String getAudUsuario() {
        return this.audUsuario;
    }

	public void setAudUsuario(String audUsuario) {
        this.audUsuario = audUsuario;
    }

	public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("AudFmodific: ").append(getAudFmodific()).append(", ");
        sb.append("AudUsuario: ").append(getAudUsuario()).append(", ");
        sb.append("Id: ").append(getId()).append(", ");
        sb.append("TimTimestam: ").append(getTimTimestam());
        return sb.toString();
    }

	public TtlsbontPK getId() {
        return this.id;
    }

	public void setId(TtlsbontPK id) {
        this.id = id;
    }

	@Transactional(value="tlbh")
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	@Transactional(value="tlbh")
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Ttlsbont attached = Ttlsbont.findTtlsbont(this.id);
            this.entityManager.remove(attached);
        }
    }

	@Transactional(value="tlbh")
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	@Transactional(value="tlbh")
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	@Transactional(value="tlbh")
    public Ttlsbont merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Ttlsbont merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }

	public static final EntityManager entityManager() {
        EntityManager em = new Ttlsbont().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	@Transactional(value="tlbh")
	public static long countTtlsbonts() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Ttlsbont o", Long.class).getSingleResult();
    }

	@Transactional(value="tlbh")
	public static List<Ttlsbont> findAllTtlsbonts() {
        return entityManager().createQuery("SELECT o FROM Ttlsbont o", Ttlsbont.class).getResultList();
    }

	public static Ttlsbont findTtlsbont(TtlsbontPK id) {
        if (id == null) return null;
        return entityManager().find(Ttlsbont.class, id);
    }

	@Transactional(value="tlbh")
	public static List<Ttlsbont> findTtlsbontEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Ttlsbont o", Ttlsbont.class).getResultList();
    }
}
